package com.geilizu.dom.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {

    public static final String[] ORIGINS={"GET","POST","DELETE","PUT","PATCH"};
    /**
     * 解决跨域问题
     * addMapping("/**") 释放所有请求
     * allowedOriginPatterns("*") 释放所有的源
     * allowedHeaders(CorsConfiguration.ALL) 允许访问的请求设置请求头信息
     * allowedMethods(ORIGINS) 设置允许访问的方式
     * allowCredentials(true) 允许请求携带Cookie
     * @param registry
     */
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOriginPatterns("*")
                .allowedHeaders(CorsConfiguration.ALL)
                .allowedMethods(ORIGINS)
                .allowCredentials(true)
                .maxAge(3600);
    }


}
